import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		/**
		 * 是否需要强制登录
		 */
		forcedLogin: false,
		hasLogin: false,
		userName: "",
		pwd: "",
		name: "",
		deptName:"",
		roles:[],
		server:{url:'http://61.136.223.52:18080/mrsp/',name:'点军宣传部服务器'},
		urls:[{name:'点军宣传部服务器',url:'http://61.136.223.52:18080/mrsp/'},{name:'学校服务器',url:'http://219.139.128.26:8082/mrsp/'}]
	},
	mutations: {
		login(state, userName) {
			state.userName = userName || '新用户';
			state.hasLogin = true;
		},
		logout(state) {
			state.userName = "";
			state.hasLogin = false;
			state.pwd='';
			state.name='';
			state.deptName='';
			state.roles=[];
		},
		setName(state,name){
			state.name=name;
		},
		setPwd(state,pwd){
			state.pwd=pwd;
		},
		setDeptName(state,deptName){
			state.deptName=deptName;
		},
		setRoles(state,roles){
			state.roles=roles;
		},
		setServerUrl(state,url){
			state.server.url=url;
		},
		changUrl(state){
			if(state.server.url==state.urls[0].url){
				state.server=state.urls[1];
			}else{
				state.server=state.urls[0];
			}
		}
		
	}
})

export default store
